﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.ComponentModel;
using System.Windows.Media.Animation;

namespace Iris.UI
{
    /// <summary>
    /// Logique d'interaction pour Win_notif.xaml
    /// </summary>
    public partial class NotificationWindow : Window
    {
        private bool closeStoryBoardCompleted = false;
        DispatcherTimer messageTimer = new DispatcherTimer();

        public NotificationWindow(string message)
        {
            InitializeComponent();

            
            this.Top = SystemParameters.PrimaryScreenHeight - this.Height;
            this.Left = SystemParameters.PrimaryScreenWidth - this.Width - 50;
            //this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            textBlock1.Text = message;

            messageTimer.Tick += new EventHandler(messageTimer_Tick);
            messageTimer.Interval = new TimeSpan(0, 0, 0, 0, 3000);
            messageTimer.Start();

        }

        void messageTimer_Tick(object sender, EventArgs e)
        {
            //Il faut stopper le timer sinon il continue toujours.
            messageTimer.Stop();
            this.Close();
        }

        private void MouseIn(object sender, MouseEventArgs e)
        {
            messageTimer.Stop();
        }

        private void MouseOut(object sender, MouseEventArgs e)
        {
            messageTimer.Start();
        }

        private void WindowClicked(object sender, MouseButtonEventArgs e)
        {
            this.Close();

        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (!closeStoryBoardCompleted)
            {
                Storyboard unloadStoryboard = (Storyboard)FindResource("Depop");
                unloadStoryboard.Begin();
                e.Cancel = true;
            }
        }

        private void closeStoryBoard_Completed(object sender, EventArgs e)
        {
            closeStoryBoardCompleted = true;
            this.Close();
        }
    }
}
